package com.ailanyin.common.model;


import cn.afterturn.easypoi.excel.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;
import java.util.List;

/**
 * 用户
 *
 * @author ailanyin
 * @version 1.0
 * @since 2021/10/15 0015 上午 10:03
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户ID")
    @Excel(name = "用户序号", width = 20)
    private Long userId;

    @ApiModelProperty(value = "部门ID")
    @Excel(name = "部门编号", width = 20)
    private Long deptId;

    @ApiModelProperty(value = "用户账号")
    @Excel(name = "登录账号", width = 20)
    private String userName;

    @ApiModelProperty(value = "用户昵称")
    @Excel(name = "用户昵称", width = 20)
    private String nickName;

    @ApiModelProperty(value = "用户邮箱")
    @Excel(name = "用户邮箱", width = 20)
    private String email;

    @ApiModelProperty(value = "手机号码")
    @Excel(name = "手机号码", width = 20)
    private String phonenumber;

    @ApiModelProperty(value = "用户性别")
    @Excel(name = "用户性别", replace = {"男_0", "女_1", "未知_2"})
    private String sex;

    @ApiModelProperty(value = "用户头像")
    private String avatar;

    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "帐号状态（0正常 1停用）")
    @Excel(name = "帐号状态", replace = {"正常_0", "停用_1"})
    private String status;

    @ApiModelProperty(value = "删除标志（0代表存在 2代表删除）")
    private String delFlag;

    @ApiModelProperty(value = "最后登录IP")
    @Excel(name = "最后登录IP", width = 20)
    private String loginIp;

    @ApiModelProperty(value = "最后登录时间")
    @Excel(name = "最后登录时间", format = "yyyy-MM-dd HH:mm:ss", width = 30)
    private Date loginDate;

    @ApiModelProperty(value = "部门对象")
    private SysDept dept;

    @ApiModelProperty(value = "角色对象")
    private List<SysRole> roles;

    @ApiModelProperty(value = "角色组")
    private Long[] roleIds;

    @ApiModelProperty(value = "岗位组")
    private Long[] postIds;

    @ApiModelProperty(value = "角色ID")
    private Long roleId;

    public SysUser() {

    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

}
